package com.qf.workqueue;

import com.qf.util.ConnectionUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;

public class Publisher {

    @Test
    public void publish() throws Exception {
        //1. 获取连接对象
        Connection connection = ConnectionUtil.getConnection();

        //2. 获取到Channel
        Channel channel = connection.createChannel();

        //3. 声明队列
        channel.queueDeclare("work_queue",true,false,false,null);

        //4. 发送消息(绑定指定队列)
        String msg = "Work Queue！！！";
        for (int i = 0; i < 10; i++) {
            channel.basicPublish("","work_queue",null,(msg + i).getBytes());
        }

        System.out.println("发送消息成功!");

        //5. 释放资源
        channel.close();
        connection.close();

    }
}
